#ifndef RECVDATA_H
#define RECVDATA_H

#include <QObject>
#include <QUdpSocket>
#include <QIODevice>
#include <QNetworkDatagram>
#include <QNetworkInterface>
#include <QSettings>
#include <QThread>
#include <QApplication>>
#include "protocolmanager.h"

#include <QDebug>

enum ConnectStatus
{
    Connected = 0,
    Disconnected
};


class RecvData : public QObject
{
    Q_OBJECT
public:
    RecvData(QIODevice *outputDevice, QObject *parent = nullptr);
    ~RecvData();

    void setOutputDevice(QIODevice *outputDevice);

signals:
    void signal_bindFailed(QString error);

    void signal_callRequest();

    void signal_callResponse(int response);

    void signal_hangUp();

    void signal_callCancel();

    void signal_port(int port);

public slots:
    void slot_start();

    void slot_hangUp();

private slots:
    void slot_writeDataToOutput();

private:
    QHostAddress hostIP();

    int analysisData(const QByteArray &data);

private:
    QIODevice *m_outputDevice;
    QUdpSocket *m_socket;
    ProtocolManager m_protocolManager;
    ConnectStatus m_connectStatus = ConnectStatus::Disconnected;
};

#endif // RECVDATA_H
